#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
ll T, n, a[N], vis[N];
void sovle1(){
	ll Ans = 0;
	for(ll i = 0; i < (1 << n); i ++){
		for(ll j = 0; j < n; j ++){
			if(i >> j & 1) vis[j] = 1;
			else vis[j] = 0;
		}
		ll x0 = 0, x1 = 0, cnt = 0;
		while(vis[x0] == 1 && x0 < n) x0 ++;
		while(vis[x1] == 0 && x1 < n) x1 ++;
		while(x0 < n){
			ll xx = x0 + 1;
			while(vis[xx] == 1 && xx < n) xx ++;
			if(xx > n) break;
			if(a[xx] == a[x0]) cnt += a[xx];
			x0 = xx; 
		}
		while(x1 < n){
			ll xx = x1 + 1;
			while(vis[xx] == 0 && xx < n) xx ++;
			if(xx > n) break;
			if(a[xx] == a[x1]) cnt += a[xx];
			x1 = xx; 
		}
		Ans = max(Ans, cnt);
	}
	cout << Ans << endl;
}
int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	cin >> T;
	while(T --){
		cin >> n;
		for(ll i = 0; i < n; i ++) cin >> a[i];
		if(n <= 15){
			sovle1();
			continue;
		}
	}
	return 0;
}
